package com.xqls.thread;

import com.xqls.redis.lock.RedisLockHelper;
import com.xqls.server.dto.FluSoketCommonDto;
import com.xqls.server.dto.SoketCommonDto;
import org.apache.log4j.Logger;

import java.util.concurrent.Callable;

/**
 * Created by Skeyedu on 2017/3/10.
 */
public class SokectRunAble   {
    private static Logger logger = Logger.getLogger(SokectRunAble.class);
    private  SoketCommonDto soketCommonDto=null;

    private  FluSoketCommonDto fluSoketCommonDto=null;

    public  SokectRunAble(SoketCommonDto soketCommonDto){
          this.soketCommonDto=soketCommonDto;
    }

    public  SokectRunAble(FluSoketCommonDto soketCommonDto){
        this.fluSoketCommonDto=soketCommonDto;
    }

    public  SokectRunAble(){

    }
    public Void call() {
        //增加并发锁
       RedisLockHelper.RedisLock redisLock=null;
        try{
            String adress ="";
            if(soketCommonDto!=null){
                adress = soketCommonDto.getAdress()+"recive";
            }
            if(fluSoketCommonDto!=null){
                adress = fluSoketCommonDto.getAdress()+"recive";
            }
            redisLock=RedisLockHelper.getInstance().newLock(adress,60000);
            if(redisLock.tryLock()){
               if(soketCommonDto!=null) soketCommonDto.operate();
               if(fluSoketCommonDto!=null) fluSoketCommonDto.operate();
            }

        }catch (Exception e){

            logger.error("接收接口处理异常",e);
        }finally {
           if( redisLock!=null)
               redisLock.unlock();
        }
        return null;

    }
}
